<template>
  <div style="width: 100%;">
    <!---->
    <el-form ref="userInfo" :model="userInfo" status-icon label-position="left"
             label-width="130px" style="width: 50%; ">
      <div style="padding-bottom: 30px">
        <h3 style="">我推广的人数：</h3>
        <el-form-item label="一级推广人数：" style="margin-bottom: 0">
          <span>{{ userInfo.expend1 }}</span>
        </el-form-item>
        <el-form-item label="二级推广人数：" style="margin-bottom: 0">
          <span>{{ userInfo.expend2 }}</span>
        </el-form-item>
      </div>

      <el-form-item label="可提现佣金：" style="margin-bottom: 15px">
        <span style="color: red">{{ userInfo.commission }} 元</span>
      </el-form-item>

    </el-form>
    <el-form ref="userInfo3" :rules="chgphoneFules" :model="userInfo3" status-icon label-position="left"
             label-width="130px" style="width: 50%; ">
      <el-form-item label="提现金额（元）：" prop="amount">
        <el-input v-model="userInfo3.amount" placeholder="提现金额" style="    width: 60%;"/>
      </el-form-item>
      <el-form-item style="margin-top:20px;">
        <el-button type="primary" :disabled="phoneDisabled" @click="chgphone">确定</el-button>
      </el-form-item>

      <el-form-item label="提现要求：" style="margin-bottom: 0">
        <span style="color: red">用户需完成实名认证；提现金额不得小于100元。</span>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {doGet, doPost} from '@/api'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'realcheck',
  filters: { },
  components: {
    Pagination
  },
  data() {
    return {
      list: [],
      userInfo3: {
        amount: ''
      },
      chgphoneFules: {
        oldMobile: [
          { amount: true, message: '提现金额不能为空', trigger: 'blur' }
        ],
      },
      userInfo: {
        userName: undefined,
        mobile: undefined,
        timeLastLogin: undefined,
        lastLoginIP: undefined,
        timeAdd: undefined,
        isChecked: undefined,
        realName: undefined,
        account: undefined,
        bankCode: undefined,
        commTotal: undefined,
        commission: undefined,
        expend1: undefined,
        expend2: undefined,
        expend3: undefined,
        extendCode: undefined,
        serverName: undefined
      },
      phoneDisabled: false,
    }
  },
  created() {
    this.getList1()
  },
  watch: {
    userInfo3: {
      handler: function(val) {
        /*let reg = /^[1][0-9]{10}$/;*/
        if (val.amount < 100) {
          this.phoneDisabled = true
        } else {
          this.phoneDisabled = false
        }
      },
      deep: true
    }
  },
  methods: {
    getList1() {
      doPost('personal.html?op=info', {}).then(response => {
        this.userInfo = response.data
        /*this.userInfo.serverName = window.location.href.replace('admin/index.html#/profile/password', '')*/
      }).catch(error => {
        this.$notify.error({
          title: '失败',
          message: error.message
        })
      })
    },
    chgphone() {
      this.$refs.userInfo3.validate((valid) => {
        if (valid && !this.loading) {
          this.loading = true
          doGet('userinfo.html?op=cashout', this.userInfo3) .then(response => {
            this.loading = false
            this.$router.back()
            this.$notify.success({
              title: '成功',
              message: '佣金提现成功'
            })
          }).catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
            this.loading = false
          })
        }
      })
    },
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
